package com.wutianyi.favority.service;

import java.util.HashMap;
import java.util.Map;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.Config;
import org.neo4j.kernel.EmbeddedGraphDatabase;

import com.wutianyi.favority.FavorityRepository;

public class FavorityServiceLocator {
	private static FavorityRepository repository;

	static {
		Map<String, String> params = new HashMap<String, String>();
		params.put(Config.USE_MEMORY_MAPPED_BUFFERS, "true");
		params.put(Config.NODE_STORE_MMAP_SIZE, "5M");
		params.put(Config.RELATIONSHIP_STORE_MMAP_SIZE, "50M");
		params.put(Config.PROPERTY_STORE_MMAP_SIZE, "50M");
		params.put(Config.STRING_PROPERTY_STORE_MMAP_SIZE, "50M");
		params.put(Config.PROPERTY_INDEX_KEY_STORE_MMAP_SIZE, "5M");
		params.put(Config.PROPERTY_INDEX_STORE_MMAP_SIZE, "5M");
		GraphDatabaseService graphDb = new EmbeddedGraphDatabase(
				"F:\\workspace\\wutianyi-favority\\favority", params);

		repository = new FavorityRepository(graphDb);
		Runtime.getRuntime().addShutdownHook(new Thread() {

			public void run() {
				repository.getGraphDb().shutdown();
			}
		});
	}

	public static FavorityRepository getRepository() {
		return repository;
	}
}
